/**
 * No copyright.
 * Class to maintain student information.
 * @author Quan Nguyen
 * @version 1.01 2008-July-24
 */
public class Student implements Comparable<Student>
{
    private int platoon;        //Platoon
    private String lastName;    //Last Name
    private String firstName;   //First Name
    private int id;             //ID Number (Four digit school assigned)
    private boolean isMale;     //Gender... I know, sexist, but it's simple.
    private int grade;          //Grade
    private int nsYear;         //NS Year
    
    /**
     * Constructs a standard student with all values.
     * @param plt platoon
     * @param last last name
     * @param first first name
     * @param idNum id
     * @param male is male or not
     * @param grd grade
     * @param ns naval science year
     */
    public Student(int plt, String last, String first, int idNum, boolean male, int grd, int ns)
    {
        platoon = plt;
        lastName = last;
        firstName = first;
        id = idNum;
        isMale = male;
        grade = grd;
        nsYear = ns;
    }
    
    /**
     * Constructs a student with no values. Well, not really. It makes 1st SGT Steven Lyon, id 1337, male, grade 13, ns5, platoon -1.
     * The idea is that the information is so ridiculous, it will be very noticeable.
     */
    public Student()
    {
        this(-1, "Lyon", "1st SGT Steven,", 1337, true, 13, 5);
    }
    
    
    /**
     * Gets the platoon.
     * @return the platoon of the student.
     */
    public int getPlatoon()
    {
        return platoon;
    }
    
    /**
     * Gets the name.
     * @return the name of the student.
     */
    public String getName()
    {
        return (firstName + " " + lastName);
    }
    
    public String getLastName()
    {
        return lastName;
    }
    
    public String getFirstName()
    {
        return firstName;
    }
    
    /**
     * Gets the ID.
     * @return the ID number of the student.
     */
    public int getID()
    {
        return id;
    }
    
    /**
     * Checks whether the student is male.
     * @return the masculinity of the student.
     */
    public boolean isMale()
    {
        return isMale;
    }
    
    /**
     * Returns the gender in a string.
     * @return the string version of the gender.
     */
    public String getGender()
    {
        if(isMale)
            return "MALE";
        return "FEMALE";
    }
    
    /**
     * Gets the grade.
     * @return the grade of the student.
     */
    public int getGrade()
    {
        return grade;
    }
    
    /**
     * Gets the NS Year.
     * @return the NS year of the student.
     */
    public int getNSYear()
    {
        return nsYear;
    }
    
    public String[] toStringArray()
    {
        String[] result = {platoon+"", lastName, firstName, id+"", getGender(), grade+"", nsYear+""};
        return result;
    }
    
    /**
     * Returns a string representation of this object.
     * @return a string representation consisting of the following format: platoon name id gender grade nsyear
     */
    public String toString()
    {
        return ("Platoon: " + platoon + " " + getName() + " ID: " + getID() + " " + getGender() + " Grade: " + getGrade() + " NS Year: " + getNSYear());
    }
    
    /**
     * Checks all fields for equality.
     * @returns if the two objects are equal.
     */
    public boolean equals(Object obj)
    {
        Student that = (Student)obj;
        return (this.toString().equals(that.toString()));
    }
    
    /**
     * Compares the objects for ordering. Note that a value of '0' does not indicate equality of objects, only an equality in order.
     * @return this items position in relative to the other.
     */
    public int compareTo(Student obj)
    {
        Student that = (Student)obj;
        return this.lastName.compareTo(that.lastName);
    }
    
    public boolean stuByName(String name)
    {
        return name.equals(getName());
    }
    
    /**
     * Returns whether or not a student attended the provided event
     * @return a student's attendance
     */
    public boolean attended(Event event)
    {
        return event.getTable().containsKey(new Integer(id));
    }
}
    